package com.wondertek.poms.service.controller;

import com.wondertek.poms.common.log.MethodLog;
import com.wondertek.poms.common.vo.GlobalCodeEnum;
import com.wondertek.poms.common.vo.ResultBean;
import com.wondertek.poms.core.service.IContentBaseFeeService;
import com.wondertek.poms.dao.pojo.ContentFeePojo;
import com.wondertek.poms.service.vo.ContentBaseFeeVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**	计费产品配置
 * @author gzx
 */
@RestController
@RequestMapping("con-base-fee")
public class ContentBaseFeeController {

	@Autowired
	private IContentBaseFeeService contentBaseFeeService;

	@PostMapping("/save")
	@MethodLog(module = "计费产品配置新增", insertDB = true, opterate = 1)
	public ResultBean update(@RequestBody ContentFeePojo contentFeePojo) {
		return contentBaseFeeService.updateProductId(contentFeePojo);
	}

	@GetMapping("/find")
	@MethodLog(module = "计费产品配置查询")
	public ResultBean find(String prdContIds) {
		if (StringUtils.isNotBlank(prdContIds)) {
			return ResultBean.ok(contentBaseFeeService.getContentBaseFeeList(prdContIds));
		} else {
			return ResultBean.error("节目id不能为空");
		}
	}

	@PostMapping("/del")
	@MethodLog(module = "计费产品配置删除", insertDB = true, opterate = 3)
	public ResultBean del(@RequestBody ContentBaseFeeVo vo) {
		for (ContentFeePojo contentFeePojo:vo.getList()) {
			ResultBean rb=contentBaseFeeService.delProductId(contentFeePojo);
			if(!GlobalCodeEnum.SUCCESS.getCode().equals(rb.getCode())){
				return rb;
			}
		}
		return ResultBean.ok("全部删除成功");
	}
}
